// pages/purchaser-details/purchaser-details.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeNames: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { price, audit, canteenId, batchOrderId} = JSON.parse(options.data)
    const [bgeinDate, endDate] = this.getDate()
    console.log(batchOrderId)
    if (audit){
      this.setData({ bgeinDate, endDate, batchOrderId, realityMoney: price, canteenId},()=>{
        this.getDetails()
      })
    }else{
      this.setData({ batchOrderId, realityMoney: price, canteenId},()=>{
        this.getDetails2()
      })
    }
    this.setData({   audit,},()=>{
    
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  changeCollapse(event) {
    this.setData({
      activeNames: event.detail
    });
  },
  getDate() {
    var nowDate = new Date();
    var cloneNowDate = new Date();
    var fullYear = nowDate.getFullYear();
    var month = nowDate.getMonth() + 1; //
    var endOfMonth = new Date(fullYear, month, 0).getDate(); // 获取本月最后一天
    function getFullDate(targetDate) {
      var D, y, m, d;
      if (targetDate) {
        D = new Date(targetDate);
        y = D.getFullYear();
        m = D.getMonth() + 1;
        d = D.getDate();
      } else {
        y = fullYear;
        m = month;
        d = date;
      }
      m = m > 9 ? m : '0' + m;
      d = d > 9 ? d : '0' + d;
      return y + '-' + m + '-' + d;
    };
    var endDate = getFullDate(cloneNowDate.setDate(endOfMonth)); //当月最后一天
    var starDate = getFullDate(cloneNowDate.setDate(1)); //当月第一天
    return [starDate, endDate]
  },
  getDetails(){
    const { bgeinDate, endDate, realityMoney, batchOrderId }=this.data
    app.reqFetch.batchOrderList({
      bgeinDate,
      endDate,
       supplierId: '1197808359328903170',
      batchOrderId
    }, (res) => {
      this.setData({ list: res.data.listMap})
    })
  },
  getDetails2() {
    const { bgeinDate, endDate, realityMoney, batchOrderId } = this.data
    app.reqFetch.getBatchOrdermx({
      supplierId: '1197808359328903170',
      batchOrderId
    }, (res) => {
      this.setData({ list: res.data.listMap })

    })
  },
  handelConfirm(){
    const { batchOrderId, canteenId}=this.data
    app.reqFetch.updateExamine({
      batchOrderId, canteenId
    }, (res) => {
  
    })
  }
})